/***************************************************************************
* Lyrics-Player                                                            *
* Copyright (C) 2012 Andrey Derevyanko <derandr@gmail.com>                 *
*                                                                          *
* This program is free software: you can redistribute it and/or modify     *
* it under the terms of the GNU General Public License as published by     *
* the Free Software Foundation, either version 3 of the License, or        *
* (at your option) any later version.                                      *
*                                                                          *
* This program is distributed in the hope that it will be useful,          *
* but WITHOUT ANY WARRANTY; without even the implied warranty of           *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
* GNU General Public License for more details.                             *
*                                                                          *
* You should have received a copy of the GNU General Public License        *
* along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
***************************************************************************/

/*! \file processThread.h
 *  \brief Thread that creates track descriptions in the form Artist - Song name
 *  \details Once a second thread reads information on the tracks
 *  \author Andrey Derevyanko <derandr@gmail.com>
 *  \version 2.1
 *  \date 10/10/2012
 *  \copyright GNU Public License
 */

#ifndef PROCESSTHREAD_H
#define PROCESSTHREAD_H

#include <QThread>
#include <QList>
#include <QDebug>
#include <QStringList>
#include <QEventLoop>
#include <QTimer>

#include <phonon/mediaobject.h>

#include "trackRecord.h"

/*! \class processThread
 *  \brief Thread of class - translator
 */
class processThread : public QThread
{
Q_OBJECT
public:
    //! Constructor
    processThread();
    //! Thread run
    void run();
    /*! \fn void setData(QList<trackRecord> *data)
     *  \brief Set the actual information on tracks
     *  \param data Pointer to a structure with tracks
     */
    void setData(QList<trackRecord> *data);
    /*! \fn void metaDataProcess()
     *  \brief Launches metadata processing
     */
    void metaDataProcess();
    QList<trackRecord> *m_data; //!< Local tracks information
    static const int max_proc_time = 100; //!< Maximal time for metadata obtaining
private:
    QTimer processTimer;
    unsigned int dataI; //!< Processed tracks counter
    Phonon::MediaObject * metaDataMedia; //!< Pointer to a processing object
    QEventLoop metaDataLoop; //!< Loop used for meta data waiting to be ready
    bool isTimeElapsed; //!< Flag if metadata were obtained in a predefined period of time
private slots:
    /*! \fn void procTimeElapsed()
     *  \brief Function that is called if metadata were not obtained in a predefined period of time
     *  \see max_proc_time
     */
    void procTimeElapsed();
signals:
    /*! \fn void updateModel()
     *  \brief Update data model
     */
    void updateModel();
};

#endif // PROCESSTHREAD_H
